import request from '@/utils/request';
import { baseurl } from "../services/baseurl";
import { hasIsSw,isLianxiSite} from '../utils/utils';;
export interface LoginParamsType {
  userName: string;
  password: string;
  user: string;
  type: string;
}
export async function accountLogin(params: LoginParamsType) {
  const data = new FormData();
  const ip = localStorage.getItem('ip')||'';
  const timestamp = new Date().getTime()+'';
  data.append('name', params.userName);
  data.append('password', params.password);
  data.append('ip', ip);
  data.append('timestamp', timestamp);
  localStorage.setItem('timestamp',timestamp)
  return request(`${baseurl}index/index/login`, {
    method: 'POST',
    data,
  });
}

export async function loginWechatgetInfo(params) {
  const data = new FormData();
  const ip = localStorage.getItem('ip')||'';
  data.append('uid', params.id);
  data.append('ip', ip);
  data.append('is_sw', params.is_sw);
  const timestamp = new Date().getTime()+'';
  data.append('timestamp', timestamp);
  localStorage.setItem('timestamp',timestamp)
  return request(`${baseurl}index/index/member_info`, {
    method: 'POST',
    data,
  });
}

export async function changePlate(params) {
  /* 切换特种设备特种培训 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  data.append('is_sw', params.is_sw);
  return request(`${baseurl}index/index/member_info_sw`, {
    method: 'POST',
    data,
  });
}

export async function recordFirstLogin(params) {
  const data = new FormData();
  data.append('id',params.id)
  if (hasIsSw()&&!isLianxiSite()) {
    const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
    data.append('is_sw', is_sw);
  }
  return request(`${baseurl}index/index/up_first`, {
    method: 'POST',
    data,
  });
}

export async function getFakeCaptcha(mobile: string) {
  return request(`/api/login/captcha?mobile=${mobile}`);
}
